abort(){
    echo "error: $@ ... aborting" >& 2
    exit 1
}

checkfile(){
    [ -f "$1" ] || abort "check file $1 failed"
}

checkbin(){
    which $1 >& /dev/null || abort "check binary $1 failed"
}

checkvar(){
    [ -n "$1" ] || abort "check variable $2 failed"
}

checkroot(){
    [ $(whoami) = "root" ] || abort "check root privilege failed"
}

# checkport <host> <port>
checkport(){
    nc -zv -w5 $1 $2 >& /dev/null || abort "check port $1:$2 failed"
}